package com.dd.cloud.open.utils;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.UUID;

/**
 * @author zk
 */
public class CodecUtils {

    public static String md5Hex(String data, String salt) {
        if (StringUtils.isEmpty(salt)) {
            salt = "";
        }
        return DigestUtils.md5Hex(salt + md5Hex(data));
    }

    public static String md5Hex(String data) {
        if (StringUtils.isBlank(data)) {
            return "";
        }
        return DigestUtils.md5Hex(data);
    }

    public static String generateSalt() {
        return StringUtils.replace(UUID.randomUUID().toString(), "-", "");
    }

}
